import requestProxy from '@/utils/request';

const { request } = requestProxy;

// 流水列表
export function getList(page, perPage, param, cancelToken) {
  return request({
    url: '/admin/financialFlow/list',
    method: 'get',
    params: {
      page,
      perPage,
      ...param
    },
    cancelToken
  });
}

// 新增流水单
export function addFinance(data) {
  return request({
    url: '/admin/financialFlow/create',
    method: 'post',
    data
  });
}

// 编辑流水单
export function editFinance(id, data) {
  return request({
    url: `/admin/financialFlow/${id}/edit`,
    method: 'put',
    data
  });
}

// 删除流水单
export function delFinance(id) {
  return request({
    url: `/admin/financialFlow/${id}/delete`,
    method: 'delete'
  });
}
// 批量删除流水单
export function batchdelFinance(data) {
  return request({
    url: '/admin/financialFlow/delete/batch',
    method: 'delete',
    data
  });
}
// 获取流水单
export function getFinance(params) {
  return request({
    url: '/admin/financialFlow/info',
    method: 'get',
    params
  });
}

// 核销列表
export function getWriteOff(page, perPage, param) {
  return request({
    url: '/admin/writeOff/list',
    method: 'get',
    params: {
      page,
      perPage,
      ...param
    }
  });
}

// 判断客户是否存在
export function clientNameExist(flowId) {
  return request({
    url: '/admin/financialFlow/clientNameExist',
    method: 'get',
    params: {
      flowId
    }
  });
}

// 核销流水订单
export function writeOffFinance(id, orderInfo) {
  return request({
    url: `/admin/financialFlow/${id}/writeOff`,
    method: 'put',
    // 由于业务需求，延长超时时间
    // retry: 50,
    // retryDelay: 1000,
    data: {
      orderInfo
    }
  });
}

// 批量核销流水订单
export function batchWriteOffFinance(data) {
  return request({
    url: '/admin/financialFlow/batchWriteOff',
    method: 'put',
    data
  });
}

// 流水详情
export function getWriteOffDetail(page, perPage, id) {
  return request({
    url: `/admin/writeOff/${id}/detail`,
    method: 'get',
    params: {
      page,
      perPage
    }
  });
}

// 撤销核销
export function cancelWriteOff(id, data = {}) {
  return request({
    url: `/admin/writeOff/${id}/cancel${data.type ? '?type=' + data.type : ''}`,
    method: 'put',
    data
  });
}

// 操作流程信息
export function getOperation(id) {
  return request({
    url: `/admin/operationRecord/${id}/list`,
    method: 'get'
  });
}

// 核销记录列表
export function getChargeReports(page, perPage, params, cancelToken) {
  return request({
    url: '/admin/chargeReport/list',
    method: 'get',
    params: {
      page,
      perPage,
      ...params
    },
    cancelToken
  });
}

// 核销入账
export function getChargeRepeal(id) {
  return request({
    url: `/admin/charge/repeal/${id}`,
    method: 'delete'
  });
}

// 重置核销
export function resetWriteOff(data) {
  return request({
    url: '/admin/writeOff/reset',
    method: 'post',
    data
  });
}
export function setRemark(data) {
  return request({
    url: '/admin/financialFlow/remark/edit/' + data.id,
    method: 'post',
    data
  });
}

// 批量撤销核销
export function batchCancelWriteOff(data) {
  return request({
    url: '/admin/writeOff/batchCancel',
    method: 'put',
    data
  });
}

// 设置无需核销金额
export function setNoWriteOff(id, data) {
  return request({
    url: `/admin/financialFlow/setNoWriteOffAmount/${id}`,
    method: 'put',
    data
  });
}

export function editLogRemark(data) {
  return request({
    url: '/admin/operationRecord/edit',
    method: 'post',
    data
  });
}

// 财务流水获取列表统计数据
export function getfinanciaStatistics(params) {
  return request({
    url: '/admin/financialFlow/statistics',
    method: 'get',
    params
  });
}

// 核销记录获取列表统计数据
export function getchargeStatistics(params, cancelToken) {
  return request({
    url: '/admin/chargeReport/statistics',
    method: 'get',
    params,
    cancelToken
  });
}

export function openAutoWriteOff(params) {
  return request({
    url: 'admin/financialFlow/autoWriteOff',
    method: 'get',
    params,
    timeout: 600000
  });
}
